import 'package:flutter/material.dart';

class FadeInDownAnimation extends StatefulWidget {
  final Widget child;
  final Duration duration;

  FadeInDownAnimation({required this.child, this.duration = const Duration(milliseconds: 500)});

  @override
  _FadeInDownAnimationState createState() => _FadeInDownAnimationState();
}

class _FadeInDownAnimationState extends State<FadeInDownAnimation>
    with SingleTickerProviderStateMixin {
  late AnimationController _animationController;
  late Animation<double> _fadeAnimation;
  late Animation<Offset> _slideAnimation;

  @override
  void initState() {
    super.initState();
    _animationController = AnimationController(
      vsync: this,
      duration: widget.duration,
    );
    _slideAnimation = Tween<Offset>(
      begin: Offset(0, -0.75),
      end: Offset(0, 0.0),
    ).animate(CurvedAnimation(
      parent: _animationController,
      curve: Curves.easeOut,
    ));
    _fadeAnimation = Tween<double>(begin: 0, end: 1).animate(
      CurvedAnimation(parent: _animationController, curve: Curves.easeOut),
    );
    _animationController.forward();
  }

  @override
  void dispose() {
    _animationController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return AnimatedBuilder(
      animation: _animationController,
      builder: (BuildContext context, Widget? child) {
        return FadeTransition(
          opacity: _fadeAnimation,
          child: SlideTransition(
              position: _slideAnimation,
              child: child),
        );
      },
      child: widget.child,
    );
  }
}